package com.yanlin.apipassenger.controller;

import com.yanlin.internalcommon.request.VerificationCodeDTO;
import com.yanlin.apipassenger.service.VerificationService;
import com.yanlin.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>标题：VerificationController</p>
 * <p>功能：乘客验证码controller</p>
 * <p>
 * 其他说明：
 * </p>
 * <p>审核：</p>
 * <p>重构：</p>
 * <p>创建日期：2025-06-04 16:58</p>
 *
 * @author yanlin
 */
@RestController
public class VerificationCodeController {

    @Autowired
    private VerificationService verificationService;

    /**
     * 获取验证码
     * @param verificationCodeDTO
     * @return
     */
    @GetMapping("/verification-code")
    public ResponseResult verificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){

        String passengerPhone = verificationCodeDTO.getPassengerPhone();
        System.out.println("请求的手机号码passengerPhone = " + passengerPhone);

        return verificationService.generateCode(passengerPhone);
    }

    /**
     * 校验验证码
     * @param verificationCodeDTO
     * @return
     */
    @PostMapping("/verification-code-check")
    public ResponseResult verificationCodeCheck(@RequestBody VerificationCodeDTO verificationCodeDTO) {
        String passengerPhone = verificationCodeDTO.getPassengerPhone();
        String verificationCode = verificationCodeDTO.getVerificationCode();
        System.out.println("手机号passengerPhone = " + passengerPhone +",验证码verificationCode = " + verificationCode);
        return verificationService.checkCode(passengerPhone, verificationCode);
    }
}